import {
    promisic
} from "../utils/util.js"
import {
    Http
} from "../utils/http.js"
class Login {

    // 微信登录获取code
    static async wxLogin(pid = 0) {
        const res = await promisic(wx.login)()
        this._tradeToken(res.code, pid)
    }

    // code换取token
    static async _tradeToken(code, pid) {
        const res = await Http.request({
            url: `/member/user_login`,
            data: {
                code,
                pid
            }
        })
        wx.setStorageSync("token", res.data)
    }

    static async checkLogin() {
        return await Http.request({
            url: "/member/check_login"
        })
    }
}

export {
    Login
}